package test;

import static org.junit.Assert.*;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.junit.Test;

public class testReflect {


	
	@Test
	public void reflect() throws Exception{
		User a = new User();
		a.setId("1");
		a.setName("john");
		try {
			System.out.println(a.getClass().getName());
			Class ul = Class.forName(a.getClass().getName());
			//Method[] methods = ul.getMethods();
			Method[] methods = ul.getMethods();
			for(Method m:methods){
				
				if(m.getName().length()>3&&m.getName().substring(0, 3).equals("set")){
					Object temp = null;
					m.invoke(a,temp);
					System.out.println(m.getName());
				}
			}
			Field[] fields = ul.getFields();
			for (Field field : fields) {
			     System.out.println(field);
			     System.out.println(field.getName());
			}
			System.out.println(a.getId()+"---------"+a.getName());
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
}
